package chapter03

/**
 * @program lu-scala01
 * @description: 特质
 * @author: zhanglu
 * @create: 2022-03-20 22:07:00
 */
object C13_Trait {

  def main(args: Array[String]): Unit = {
    val student = new Student13
    student.sayHello()
    student.study
    student.dating
    student.play()
  }

}

class Person13{
  val name: String = "person"
  val age: Int = 18
  def sayHello(): Unit ={
    println("hello from person")
  }
}

trait Young{
  //声明抽象和非抽象属性方法
  val age: Int
  var sex: String = _
  val name: String = "young"
  def play(): Unit ={
    println(s"young people $name is playing")
  }
  def dating: Unit
}

class Student13 extends Person13 with Young {

  //重写冲突的属性
  override val name: String = "student"
  sex = "男"

  //实现抽象方法
  def dating: Unit = {
    println(s"student $name is dating")
  }
  def study: Unit ={
    println(s"student $name is studing")
  }

  override def sayHello(): Unit = {
    super.sayHello()
    println(s"hello from student $name")
  }
}

